package Year21_Month10.day1017;

public class MyTest {
    Persion[] array;
    int size;

    //构造器直接初始化数组
    public MyTest(int size) {
        array = new Persion[size];
        size = 0;
    }

    //添加元素
    public void add(Object data){
        //先检测是否有位置进行添加
        if(size == array.length){
            System.out.println("位置已满");
        }
        //如果没满就进行尾插
        array[size++] = (Persion) data;
    }

    //获取元素
    public Persion get(int data){
        if(data > size){
            System.out.println("下标越界了");
        }

        return array[data];
    }
    //获取数组长度
    public int size(){
        return size;
    }

    public static void main(String[] args) {
        MyTest myArray = new MyTest(10);
        myArray.add(new Persion("HanMeiMei", "女", 12));
        myArray.add(new Persion("LiLeiLei", "男", 13));
        myArray.add(new Persion("LiLeiLei", "男", 13));
        myArray.add(new Persion("LiLeiLei", "男", 13));
        System.out.println(myArray.size());
    }

}
